package com.example.demo.service.impl;

import com.example.demo.entity.Result;
import com.example.demo.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class RoleServiceImpl {
    @Autowired
    private RoleMapper roleMapper;
    public Result getRole(Map<String, Object> params) {
        List<Map<String,Object>> list=roleMapper.getRole(params);
        return Result.ok(list);
    }

    @Transactional
    public Result insertRole(Map<String, Object> params) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String roleId = UUID.randomUUID().toString();
        params.put("roleId",roleId.substring(0,5));
        params.put("crtDt", sdf.format(new Date()));
        roleMapper.insertRole(params);
        return Result.ok("新增角色成功");
    }

    public Result deleteRole(Map<String, Object> params) {
        roleMapper.deleteRole(params);
        return Result.OK_EMPTY;
    }
}
